{
    title:  'Generating Components',
    crumbs: [
        { "User's Guide": 'index.html' },
    ],
}
            <h2>Generating Controllers</h2>
            <a id="controllers"></a>
            <p>Controllers are the primary mechanism for responding to client requests. 
            Controllers may be generated directly or as part of a scaffold that includes database 
            schema and web pages. Before generating a controller, you must have installed an ESP skeleton
            that includes support for generating controllers such as: 
                <em>esp-skeleton</em>, 
                <em>esp-html-skeleton</em> or
                <em>esp-angular-skeleton</em>.</p>

            <p>To generate a controller, use <em>esp generate controller</em>.</p>

            <code class="inverted">$ <b>esp generate controller NAME [actions...]</b></code>

            <p>This will create the named controller in the <em>controllers</em> directory. A controller manages 
            requests to the web application. The controller action methods are invoked by ESP to respond to 
            client requests and generate responses.</p>

            <p>If no actions are requested when generating, <em>esp</em> will create a controller with 
            an initialization function but without any actions. If actions are specified, <em>esp</em> 
            will create an empty action method for each requested action. You can edit the
            controller source to meet your needs.</p>
            <p>If you use the command:</p>

            <code class="inverted">$ <b>esp generate controller admin edit login logout command</b></code>
            <p>The following controller code will be generated. There is one function generated for each action 
            and a call to <em>espDefineAction</em> is added to register the controller. The <em>esp_controller_admin</em>
            initialization function is invoked once when the controller is first loaded.</p>

            <code class="inverted">#include "esp.h"

static void edit() {}
static void login() {}
static void logout() {}
static void command() {}

ESP_EXPORT int esp_module_admin(HttpRoute *route) 
{
    espDefineAction(route, "admin-cmd-edit", edit);
    espDefineAction(route, "admin-cmd-login", login);
    espDefineAction(route, "admin-cmd-logout", logout);
    espDefineAction(route, "admin-cmd-command", command);
    return 0;
}
</code>
            <a id="database"></a>
            <h2>Generating Database Tables</h2>
            <p>Database schema can be created and modified via the <em>esp</em> command. 
            This will create a database table with fields of the required types.</p>

            <code class="inverted">$ <b>esp generate table NAME [field:type ...]</b></code>

            <p>If <em>field:type</em> values are supplied, the database will be updated for each specified field of 
            the requested type. The valid database types are: binary, boolean, date,
            datetime, decimal, float, integer, number, string, text, time, timestamp. </p>

            <a id="migrations"></a>
            <h2>Generating Migrations</h2>
            <p>Database migrations are mini programs which modify the database schema or content. You can create database
            migrations by the "<em>esp generate migration</em>" command. This command generates a migration for a
            specific model by creating or removing tables and columns. To generate a migration:</p>

            <code class="inverted">$ <b>esp generate migration description MODEL [field:type ...]</b></code>

            <p>This will create a migration script under the <em>migrations</em> directory. Migration scripts filenames are
            time stamped and use the description as part of the filename for the migration script (so keep it short and
            sweet and don't use spaces!).</p>
            <p>For each specified <em>field:type</em> pair, esp will generate add column code in the migration
            script. If the --reverse switch is specified, then remove column code will be generated. To change the type
            or name of a column, remove then re-add the column. </p>
            
            <a id="runMigrations"></a>
            <h2>Running Migrations</h2>
            <p>Migration scripts can be run via the "<em>esp migrate</em>" command. Without other parameters, the
            command will run all migrations that have not yet been applied to the database. You can also use
            "<em>esp migrate forward</em>" to apply the next unapplied migration. Similarly, "<em>esp migrate
            backward</em>" will reverse the last applied migration. You can also use "<em>esp migrate NNN</em>" to
            migrate forward or backward to a specific migration. NNN is the migration sequence number which is the
            number at the start of the migration script file name.</p>
            <p>Migrations are often under used. They are much more important than most people realize. Being able
            to effectively create and manage database test data greatly simplifies this aspect of development and testing.</p>
            
            <a id="scaffolds"></a>
            <h2>Generating Scaffolds</h2>
            <p>Scaffolds enable you to quickly create sections of your application. A scaffold provides CRUD 
            functionality (create, read, update and delete) for a database table. Generating a scaffold 
            will create a database table, controller and actions to add-edit-delete. Depending on the 
            skeleton, a set of views may also be generated that provide add, edit and list functionality 
            for a database table. The <em>esp-skeleton</em> does not provide scaffold view. The
            <em>esp-html-skeleton</em> provides basic HTML view pages, and the <em>esp-angular-skeleton</em>
            provide client-side Angular views.</p>

            <p>To generate a scaffold:</p>

            <code class="inverted">$ <b>esp generate scaffold NAME [field:type ...]</b></code>

            <p>This will create a scaffold for the named database table and will generate a controller of the same name. 
            If field:type values are supplied, the database will be updated with columns for
            each specified field of the requested type. The valid database types are: <em>binary, bool, date, 
            float, int, string, text</em>. The scaffold controller will include a create, get, index, remove 
            and update actions. </p>

            
